<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<p>
			<h4>点击下面框框：红绿交替</h4></p>
		<div style="width: 200px; height: 200px; border: 1px solid red;" id="div" onclick="change()">
			<script>
				function change() {
					var bg = document.getElementById('div');
					bg.style.backgroundColor =
						(bg.style.backgroundColor == 'red' ? 'green' : 'red');
				}
			</script>

		</div>
	</body>

</html>